import { addZero } from "@/utils/common";

// 历史记录聊天时间
const formatDate = date => {
  if (!date) {
    return "";
  }
  if (date && !(date instanceof Date)) {
    date = new Date(date);
  }
  // const year = date.getFullYear();
  // const month = date.getMonth() + 1;
  // const day = date.getDate();
  const hour = date.getHours();
  const minute = date.getMinutes();
  return `${addZero(hour, 2)}:${addZero(minute,2)}`;
};
// 历史记录时间区分标题
const titleTimeFormat = date => {
  if (!date || !(date instanceof Date)) {
    date = new Date(date);
  }
  const year = date.getFullYear();
  const month = date.getMonth() + 1;
  const day = date.getDate();
  // const hour = date.getHours();
  // const minute = date.getMinutes();
  // const second = date.getSeconds();
  return `${year}年${addZero(month)}月${addZero(day)}日`;
};

// 历史记录时间区分标题
const knowledgeTimeFormat = date => {
  if (!date) {
    return "";
  }
  if (date && !(date instanceof Date)) {
    date = new Date(date);
  }
  const year = date.getFullYear();
  const month = date.getMonth() + 1;
  const day = date.getDate();
  const hour = date.getHours();
  const minute = date.getMinutes();
  return `${year}年${addZero(month, 2)}月${addZero(day, 2)}日 ${addZero(
    hour,
    2
  )}:${addZero(minute, 2)}`;
};
export { formatDate, titleTimeFormat, knowledgeTimeFormat };
